package com.neborosoft.lib;

import com.neborosoft.lib.API_8.Collections;

import java.util.LinkedHashMap;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * User: CM
 * Date: 07.01.13
 * Time: 23:57
 * To change this template use File | Settings | File Templates.
 */
public final class Sets {
    public static interface RemovePolicy<T>{
        boolean shouldBeRemoved(T object);
    }

    public static <T> Set<T> accessOrderedSet(){
        return Collections.newSetFromMap(new LinkedHashMap<T, Boolean>(100,0.75f,true));
    }

    public static <T> Set<T> accessOrderedSet(final RemovePolicy<T> removePolicy){
        return Collections.newSetFromMap(new LinkedHashMap<T, Boolean>(100,0.75f,true){
            @Override
            protected boolean removeEldestEntry(Entry<T, Boolean> eldest) {
                return removePolicy.shouldBeRemoved(eldest.getKey());
            }
        });
    }
}
